package TP2.sorters;

import anaydis.sort.SorterType;

import java.util.Comparator;
import java.util.List;

public class SelectionSorter extends AbstractSorter {

    public SelectionSorter(){
        this(SorterType.SELECTION);
    }

    protected SelectionSorter(final SorterType type){
        super(type);
    }

    public <T> void sort(Comparator<T> comparator, List<T> list){
        int n = list.size();
               for (int i = 0; i < n; i++){
                   int min = i;
                   for (int j = i+1; j < n; j++){
                       if (greater(comparator, list, min, j)){
                           min = j;
                       }
                   }
                   if(i!=min){
                       swap(list, i, min);
                   }
               }
    }

}
